package me.tuyou.wordcount;

import me.tuyou.common.LineSplitter;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.AggregateOperator;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;

/**
 * 单词统计(批处理)
 */
public class BatchWordCountTest {

	public static void main(String[] args) throws Exception {

		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
		DataSource<String> dataSource = env.fromElements("flink batch demo", "batch demo", "demo");
		AggregateOperator<Tuple2<String, Integer>> sum = dataSource
				.flatMap(new LineSplitter())
				.groupBy(0)
				.sum(1);
		sum.print();
	}
}
